﻿#define _CRT_SECURE_NO_WARNINGS 1
/*#include <stdio.h>
int Max(int x, int y)
{
	if (x > y)
		return x;
	else
		return y;
}
int main()
{
	int num1 = 100;
	int num2 = 200;
	int max = 0;
	max = Max(num1, num2);
	printf("max = %d\n", max);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int a = 1;
	int b = 2;
	if (2 == a)
	{
		if (b == 2)
			printf("hehe\n");
	}
		else
			printf("haha\n");
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int i = 1;
	while (i <= 100)
	{
		if (1 == i % 2)
			printf("%d ", i);
		i++;
	}
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int a = 1;
	while (a <= 10)
	{
		printf("%d\n", a);
		a++;
	}
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	printf("%c\n", 97);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int ch = 0;
	while ((ch = getchar()) != EOF)
	{
		putchar(ch);
	}
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	for (int i = 1; i <= 10; i++)
		printf("%d\n", i);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	for (int i = 0; i < 10; i++)
		
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int i = 0;
	while (i<=10)
	{
		if (5 == i)
			continue;
			printf("%d\n", i);
			i++;
	}
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int i = 0;
	int n = 0;
	int ret = 1;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		ret = ret * i;
	}
		printf("ret = %d\n", ret);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int n = 0;
	int ret = 1;
	int sum = 0;
	for (n = 1; n <= 3; n++)
	{
		ret = ret * n;
		sum = sum + ret;
	}
	printf("sum = %d\n", sum);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int i = 0;
	for (i = 1; i <= 100; i++)
		if (0 == i % 3)
		{
			printf("i = %d\n", i);
		}
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int year = 0;
	int count = 0;
	for (year = 1000; year <= 2000; year++)
	{
		if ((0==year%4&&0!=year%100)||(0==year%400))
		{
			printf("%d ", year);
			count++;
		}
	}
	printf("count = %d\n", count);
	return 0;
}*/
/*#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void menu()
{
	printf("**********************************\n");
	printf("*******  1. play  2. exit  *******\n");
	printf("**********************************\n");
}
void game()
{
	int ret = 0;
	int guess = 0;
	ret = rand()%100+1;
	//printf("%d\n", ret);
	while (1)
	{
		printf("猜猜数字:>");
		scanf("%d", &guess);
		if (guess > ret)
		{
			printf("猜大了\n");
		}
		else if (guess < ret)
		{
			printf("猜小了\n");
		}
		else
		{
			printf("恭喜你,猜对了\n");
			break;
		}
	}
}
int main()
{
	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("请选择:>");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("退出游戏\n");
			break;
		default:
			printf("选择错误\n");
			break;
		}
	} while (input);
	return 0;
}*/
/*#include <stdio.h>
#include <string.h>
int main()
{
	char arr1[] = "bit";
	char arr2[20] = "##########";
	strcpy(arr2, arr1);
	printf("%s\n", arr2);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int a = -1;
	//int b = 2;
	//int i = a & b;//用的是补码加减
	//printf("%d\n",  i);
	printf("%d\n", a << 1);//用补码
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	printf("%d", printf("%d", printf("%d", 43)));
	return 0;
}*/
/*#include <stdio.h>
int Fib(int a)
{
	int b = 1;
	int c = 1;
	int d = 1;
	while (a > 2)
	{
		d = c + b;
		b = c;
		c = d;
		a--;
	 }
	return d;
}
int main()
{
	int a = 0;
	int i = 0;
	scanf("%d", &a);
	i = Fib(a);
	printf("%d ", i);
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int arr[] = { 100,200,300,400,500,600 };
	printf("%p", arr);
	printf("\n%p", &arr[0]);
	printf("\n%d", *arr);
	printf("\n%d", *(arr+1));
	return 0;
}*/
/*#include <stdio.h>
void bubble_sort(int arr[],int sz)
{
	int i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int flag = 1;
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if( arr[j] > arr[j + 1])
			{
				int tmp = arr[j];
				arr[j] = arr[j + 1];
			    arr[j + 1] = tmp;
				flag = 0;
			}
		}
		if (flag==1)
		{
			break;
		}
	}
}
int main()
{
	long arr[] = {1,0,3,7,6,5};
	int i = 0;
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz);
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}*/
/*#include <stdio.h>
int main()
{
	int x = 1;

	double y = 2.666666666666;
	double z = x + y; 
	printf("%lf", z);
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	printf("please input score:>");
	scanf("%d",&i);
	switch (i/5)
	{
	case 20:
	case 19:
	case 18:
		printf("A");
		break;
	case 17:
	case 16:
	case 15:
		printf("B");
		break;
	case 14:
	case 13:
	case 12:
		printf("C");
		break;
	default:
		printf("D");
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	int sum = 0;
	for (a = 1; a < 10; a++)
	{
		for (b = 1; b < a+1; b++)
		{
			sum = a * b;
			printf("%d*%d=%d\t", b, a, sum);
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>
void menu()
{
	printf("****************************\n");
	printf("****** 1.play   0.exit *****\n");
	printf("****************************\n");
}
void game()
{

}
void test()
{
	int a = 0;
	do
	{
		menu();
		printf("请输入:>");
		scanf("%d", &a);
		switch (a)
		{
		case 1:
			game();
			break;
		case 0:
			printf("退出游戏");
			break;
		default:
			printf("输入错误，请重新选择");
			break;
		}
	} while (a);
}
int main()
{
	test();
	return 0;
}
#include <stdio.h>
int main()
{
	float a = 5.0 / 2;
	printf("%f", a);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = -1;
	int b = a >> 1;
	printf("%d", b);
	return 0;
}
#include <stdio.h>
int main()
{
	double x = 0;
	double y = 0;
	printf("please input x :>");
	scanf("%lf",&x);
	if (x < 5)
		y = (x > 0 ? x : -x);
	else if (x >= 5 && x < 20)
		y = (3 * x * x - 2 * x + 1);
	else
		y = x / 5;
	printf("%lf", y);
	return 0;
}
#include <stdio.h>
int main()
{
	double s = 0;
	double x = 0;
	printf("请输入应得工资:>");
	scanf("%lf", &s);
	if (s >= 5000)
	{
		x = (330 + (s - 5000) * 0.15);
	}
	else
		switch ((int)(s / 1000))
		{
		case 0:
			x = 0, s = s;
			break;
		case 1:
			x = ((s - 1000) * 0.05);
			break;
		case 2:
			x = ((s - 2000) * 0.08 + 50);
			break;
		case 3:
		case 4:
			x = ((s - 3000) * 0.1 + 130);
			break;
		default :
			printf("输入错误");
		}
	s -= x;
	printf("纳税款为:>%f", x);
	printf("实得工资%lf", s);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 5, b = 4, c = 3, d = 0, e = 0, f = 0, g = 0;
	e = a > b > c;
	f = a && b || c;
	g = c && d && a++;
	printf("a = %d,e = %d,f = %d,g = %d", a, e, f, g);
	return 0;
	}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	int c = 0;
	for (a = 1; a <= 9; a++)
	{
		for (b = 1; b <= a; b++)
		{
			c = a * b;
			printf("%d*%d=%d\t", b, a, c);
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	double a = 1.0;
	int sign = 1;
	double sum = 0;
	for (i = 1; a >= 1e-6; i++)
	{
		a = 1.0 / (2 * i - 1);
		sum += a*sign;
		sign = -sign;
	}
	printf("pi = %lf", 4 * sum);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	int n = 0;
	printf("please input n :>");
	scanf("%d", &n);
	for (a = 1; a <= n; a++)
	{
		printf("    ");
		for (b = 1; b <= a; b++)
		{
			printf("*");
		}
		printf("\n");
	}
	for (a = n - 1; a >= 1; a--)
	{
		printf("    ");
		for(b  = n-a;b >= 1;b--)
		printf(" ");
		for (b = 1; b <= a; b++)
		{
			printf("*");
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	int n = 0;
	printf("please input n :>");
	scanf("%d", &n);
	for (a = 1; a <= n; a++)
	{
		printf("    ");
		for (b = n - a; b >= 1; b--)
		{
			printf(" ");
		}
		for (b = 1; b <= (2 * a - 1); b++)
		{
			printf("*");
		}
		printf("\n");
	}
	return 0;
}


#include<stdio.h>
int main()
{
	int a, b;
	int c = 1;
	printf("请输入一个数：\n");
	scanf("%d", &a);
	for (b = 2; b < a; b++) {

		if (a % b == 0) {
			c = 0;
		}

	}
	if (c == 0) {
		printf("该数不为素数\n");
	}
	else {
		printf("该数为素数\n");
	}
	return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
	int a = 0;
	int b = 0;
	printf("please input b :>");
	scanf("%d", &b);
	for (a = 2; a <= sqrt(b); a++)
	{
		if (b % a == 0)
			break;
	}
	if (a <= sqrt(b))
		printf("%d不是素数", b);
	else
		printf("%d是素数", b);
	return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
	int a = 100;
	int b = 0;

	for (a = 100; a <= 200; a++)
	{
		for (b = 2; b <= sqrt(a); b++)
		{

			if (a % b == 0)
				break;

		}
		if (b > sqrt(a))
			printf("%d ", a);
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int a, b;
	float x, y;
	char c1, c2;
	scanf("a = %d,b = %d", &a, &b);
	scanf("%f%e", &x, &y);
	scanf("%c%c", &c1, &c2);
	printf("a = %d,b = %d\n",a,b);
	printf("x = %f,y = %e\n",x,y);
	printf("c1 = %c,c2 = %c\n",c1,c2);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 4;
	int x = 0;
	x = a;
	x = x + a;
	printf("%d,%d", x, a);
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int count = 0;
	for (i = 2; i;)
	{
		printf("%d ", i--);
		count++;
	}
	printf("%d", count);
	return 0;
}
#include <stdio.h>
	int c1 = 0;
	int c2 = 0;
	int c3 = 0;
	void fun(long n)
	{
		c1 = c2 = c3 = 0;
		while (n)
		{
			switch (n % 10)
			{
			case 1:
				c1++;
				break;
			case 2:
				c2++;
				break;
			case 3:
				c3++;
				break;
			default :
				;
			}
			n = n / 10;
		}
	}
	int	main()
	{
		long n = 123114350;
		fun(n);
		printf("\nThe result :>\n");
		printf("n = %ld c1 = %d c2 = %d c3 = %d", n, c1, c2, c3);
		return 0;
	}
#include <stdio.h>
int main()
{
	int a, b;
	printf("please input two numbers:>");
	while (scanf("%d%d", &a, &b) == 2)
	{
		if (a > b)
			printf("%d > %d\n", a, b);
		else if (a == b)
			printf("%d = %d\n", a, b);
		else
			printf("%d < %d\n", a, b);
	}
	return 0;
}
#include <stdio.h>
int main()
{
	printf("%d\n", 11 % -5);//1
	printf("%d\n", -11 % -5);//-1
	printf("%d\n", -11 % 5);//-1
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 3; int b = 4; int c = 5;

	a = b = c + 5;
		printf("a = %d\nb = %d\nc = %d" , a, b, c);
	return 0;
}
#include <stdio.h>
int main()
{
	float a = 0.467f;
	printf("%.2f", a);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	for (a = 3; a <= 100; a += 3)
		printf("%d ", a);
	return 0;
}

#include <stdio.h>
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	int d = b * b - 4 * a * c;
	if (a + b > c && a + c > b && b + c > a)	
	{
		printf("Equilateral triangle!");

		if (a == b || b == c || a == c)
			printf("Isosceles triangle!");
		else
			printf("Ordinary triangle!");
	}
	else
		printf("Not a triangle!");
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int sign = 1;
	double sum = 0;
	for (a = 1; a <= 100; a++)
	{
		sum += sign * (1.0 / a);
		sign = -sign;
	}
	printf("%lf", sum);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int count = 0;
	for (a = 1; a <= 100; a++)
	{
		if (a % 10 == 9)
			count++;
		if (a / 10 == 9)
			count++;
	}
	printf("%d", count);
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int count = 0;
	for (i = 1000; i <= 2000; i++)
	{
		if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
			printf("%d ", i);
		count++;
	}
	printf("\n%d", count);
	return 0;
}

#include <stdio.h>
int main()
{
	int a, b, c;
	int tmp = 0;
	scanf("%d%d%d", &a, &b, &c);
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	if (a < c)
	{
		tmp = a;
		a = c;
		c = tmp;
	}
	if (b < c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	printf("%d %d %d", a, b, c);
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int arr[10] = { 5,7,8,4,11,9,1,3,2,10 };
	int MAX = arr[0];
	for (i = 1; i <= 9; i++)
	{
			if (MAX < arr[i])
			{
				MAX = arr[i];
			}
	}
	printf("%d", MAX);
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int n = 0;
	int j = 0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		printf("     ");
		for (j = 1; j <= i; j++)
		{
			printf("*");
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	for (a = 1; a <= 9; a++)
	{
		for (b = 1; b <= a; b++)
		{
			printf("%d*%d=%-2d\t", b, a, a * b);
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>
int main()
{
	char arr1[4] = { 'a','b','c' };
	char arr2[3] = { "abc" };
	printf("%s\n", arr1);
	printf("%s\n", arr2);
	return 0;
}

#include <stdio.h>
int main()
{
	int i = 0;
	int arr[5] = { 1,2,3,4,5 };
	printf("arr = %d,arr[0] = %d,arr[4] = %d\n", arr, arr[0], arr[4]);
	for (i = 0; i <= 4; i++)
	{
		printf("&arr[%d] = %d ",i, &arr[i]);
	}
	printf("\n");
	for (i = 0; i <= 4; i++)
	{
		printf("arr[%d] = %d ", i, arr[i]);
	}
	int arr[2][3] = { 1,2,3,4,5,6 };
	printf("arr[0] = %d,arr[0][0] = %d,arr = %d", arr[0], arr[0][0], arr);
	return 0;
}
#include <stdio.h>
int main()
{
	printf("%d\n", 'A' != 'a');
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 2;
	if (a == 1)
		if (b == 2)
			printf("hehe\n");
    else
			printf("haha\n");
	return 0;
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void menu()
{

	printf("*****        *****\n");
	printf("***** 1.play *****\n");
	printf("***** 0.exit *****\n");
	printf("*****        *****\n");
}
void game()
{
	int a = 0;
	int b = rand() % 100 + 1;
	int count = 5;
	while (1)
	{
		if (count == 0)
		{
			break;
		}
		printf("你还有%d次机会\n", count--);
		printf("请输入值:>");
		scanf("%d", &a);
		if (a < b)
		{
			printf("猜小了\n");
		}
		else if (a > b)
		{
			printf("猜大了\n");
		}
		else
		{
			printf("恭喜你！猜对了！答案是%d\n", b);
			break;
		}
	}
}
int main()
{
	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("please choose :>");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("退出游戏");
			break;
		default:
			printf("输入错误请重新输入\n");
			break;
		}
	} while (input);
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	for (a = 1; a <= 9; a++)
	{
		for (b = 1; b <= a; b++)
		{
			printf("%d*%d=%-2d\t", b, a, a * b);
		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
int main()
{
	int a, b;
	int c = 0;
	int tmp = 0;
	printf("please input two numbers:>");
	scanf("%d%d", &a, &b);
	while (1)
	{
		c = a % b;//a % b = c;
		if (c == 0)
		{
			printf(" %d是最大公约数", b);
			break;
		}
		else
		{
			a = b;
			b = c;
		}
	}
	return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
	int a = 0;
	int i = 0;
	printf("please input a number:>");
	scanf("%d", &a);
	for (i = 2; i <= sqrt(a); i++)
	{
		if (a % i == 0)
		{
			printf("%d不是素数\n",a);
			return;
		}
	}
	printf("%d是素数\n", a);
	return 0;
}
#include <stdio.h>
int main()
{
	int arr[10] = { 0 };
	int i = 0;
	double sum = 0.0;
	for (i = 0; i <= 9; i++)
	{
		scanf("%d", &arr[i]);
		sum += arr[i];
	}
	printf("%lf", sum / 10);
	return 0;
}
#include <stdio.h>
int main()
{
	int a;
	int i = 0;
	printf("please input a number:>");
	while (scanf("%d", &a) != EOF)
	{
		for (i = 1; i <= a; i++)
		{
			int j = 0;
			for (j = 1; j <= a; j++)
			{
				printf("*");
			}
			printf("\n");
		}
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int n;
	printf("please input n(3<=n<20):>");
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
	{
		if (i == 1 || i == n)
		{
			int j = 0;
			for (j = 1; j <= n; j++)
			{
				printf("* ");
			}
			printf("\n");
		}
		else
		{
			printf("*");
			int j = 0;
			for (j = 1; j<= 2*n - 3; j++)
			{
				printf(" ");
			}
			printf("*\n");
		}
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int j = 0;
	int arr1[2][3] = { 0 };
	for (i = 0; i <= 1; i++)
	{
		for (j = 0; j <= 2; j++)
		{
			scanf("%d", &arr1[i][j]);
		}
	}
	for (i = 0; i <= 2; i++)
	{
		for (j = 0; j <= 1; j++)
		{
			printf("%d ", arr1[j][i]);
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>

int main()

{

	int i = 0;

	int n;


	while ((scanf("%d", &n)) != EOF)
	{

		for (i = 1; i <= n; i++)

		{

			if (i == 1 || i == n)

			{

				int j = 0;

				for (j = 1; j <= n; j++)

				{

					printf("* ");

				}

				printf("\n");

			}

			else

			{

				printf("*");

				int j = 0;

				for (j = 1; j <= 2 * n - 3; j++)

				{

					printf(" ");

				}

				printf("*\n");

			}

		}
	}
	return 0;
}

#include <stdio.h>
int main()
{
	int i = 0;
	int arr[10] = { 0 };
	for (i = 0; i <= 9; i++)
	{
		scanf("%d", &arr[i]);
	}
	for (i = 9; i >= 0; i--)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int j = 0;
	int n = 0;
	while ((scanf("%d", &n)) != EOF)
	{
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (i == j || i == (n - j + 1))
				{
					printf("*");
				}
				else
				{
					printf(" ");
				}
			}
			printf("\n");
		}
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	char tmp = 0;
	char arr1[20] = "***********";
	char arr2[20] = "Hello World";
	for (i = 0; i <= 19; i++)
	{
		tmp = arr1[i];
		arr1[i] = arr2[i];
		arr2[i] = tmp;
		printf("%c", arr1[i]);
	}
	printf("\n");
	for (i = 0; i <= 19; i++)
	{
		printf("%c", arr2[i]);
	}
	return 0;
}


#include <stdio.h>
int main()
{
	float y;
	scanf("%e", &y);
	printf("%f", y);
	return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
	double x;
	scanf("%lf", &x);
	if (x < 5)
	{
		printf("%lf", fabs(x));
	}
	else if (x < 20)
	{
		printf("%lf", 3 * x * x - 2 * x + 1);
	}
	else
	{
		printf("%lf", x / 5.0);
	}
	return 0;
}
#include <stdio.h>
long fac(int n)
{
	long k;
	printf("n = %d\n", n);
	if (n == 0 || n == 1)
	{
		k = 1;
	}
	else
	{
		k = fac(n - 1)*n;
	}
	printf("%d!=%d\n", n, k);
	return k;
}
int main()
{
	int a;
	printf("input data:>");
	scanf("%d", &a);
	printf("main:%d!=%d\n", a, fac(a));
	return 0;
}
#include <stdio.h>//转置矩阵
int main()
{
	int i = 0;
	int j = 0;
	int n, m;
	int arr[10][10] = { 0 };
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &arr[i][j]);
		}
	}
	//for (i = 0; i < m; i++)
	//{
	//	for (j = 0; j < n; j++)
	//	{
	//		printf("%d ", arr[j][i]);
	//	}
	//	printf("\n");
	//}
	return 0;
}
#include <stdio.h>//转置矩阵的补充
int main()
{
	int i = 0;
	int j = 0;
	int n, m;
	int arr1[10][10] = { 0 };
	int arr2[10][10] = { 0 };
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &arr1[i][j]);
		}
	}
	//for (i = 0; i < m; i++)
	//{
	//	for (j = 0; j < n; j++)
	//	{
	//		arr2[i][j] = arr1[j][i];
	//	}
	//}
	//for (i = 0; i < m; i++)
	//{
	//	for (j = 0; j < n; j++)
	//	{
	//		printf("%d ", arr2[i][j]);
	//	}
	//	printf("\n");
	//}
	//return 0;
}
#include <stdio.h>//输入两个升序排列的序列，将两个序列合并为一个有序序列并输出
int main()
{
	int n, m, tmp;
	int i = 0;
	scanf("%d %d", &n, &m);
	int arr[2000] = { 0 };
	for (i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}
	for (i = n; i < n + m; i++)
	{
		scanf("%d", &arr[i]);
	}
	//for (i = 0; i < m + n; i++)
	//{
	//	int j = 0;
	//	for (j = (i + 1); j < n + m; j++)
	//	{
	//		if (arr[i] > arr[j])
	//		{
	//			tmp = arr[i];
	//			arr[i] = arr[j];
	//			arr[j] = tmp;
	//		}
	//	}
	//}
	//for (i = 0; i <= (n + m - 1); i++)
	//{
	//	printf("%d ", arr[i]);
	//}
	return 0;
}
#include <stdio.h>//输入两个升序排列的序列，将两个序列合并为一个有序序列并输出，补充。
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int arr1[2000] = { 0 };
	int arr2[2000] = { 0 };
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr1[i]);
	}
	for (int j = 0; j < m; j++)
	{
		scanf("%d", &arr2[j]);
	}
	int i = 0;
	int j = 0;
	while (i < n && j < m)
	{
		if (arr1[i] < arr2[j])
		{
			printf("%d ", arr1[i]);
			i++;
		}
		else
		{
			printf("%d ", arr2[j]);
			j++;
		}
	}
		while (j < m)
		{
			printf("%d ", arr2[j]);
			j++;
		}
		while (i < n)
		{
			printf("%d ", arr1[i]);
			i++;
		}
	return 0;
}
#include <stdio.h>//static及各变量的储存属性
int n = 1;
void func()
{
	static int a = 2;
	int b = 5;
	a += 2;
	b += 5;
	n += 12;
	printf("a = %d,b = %d,n = %d\n", a, b, n);
}
int main()
{
	int a = 0, b = -10;
	printf("a = %d,b = %d,n = %d\n", a, b, n);
	func();
	printf("a = %d,b = %d,n = %d\n", a, b, n);
	func();
	return  0;
}
#include <stdio.h>//简单递归
static int fun(int n)
{
	if (1 == n)
	{
		return 10;
	}
	else if(n > 1)
	{
		return fun(n - 1) + 2;
	}
	else
	{
		printf("Error!!!");
	}
}
int main()
{
	int n = 0;
	printf("Enter n:>");
	while ((scanf("%d", &n)) != EOF)
	{
		printf("The result:> %d\n\n", fun(n));
	}
	return 0;
}
#include <stdio.h>//升序二分查找法
int main()
{
	int n;
	scanf("%d", &n);
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int left = 0;
	int right = sizeof(arr) / sizeof(arr[0])-1;
		while (left <= right)
		{
			int mid = (left + right) / 2;//优化  mid = left + (right - left)/2;
			if (n > arr[mid])
			{
				left = mid + 1;
			}
			else if (n < arr[mid])
			{
				right = mid - 1;
			}
			else
			{
				printf("找到了下标是%d\n", mid);
				return;
			}
		}
		printf("找不到\n");
	return 0;
}
#include <stdio.h>
int main()
{
	int n = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			printf("%d*%d=%-3d", j, i, j * i);
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>
static int year(int n)
{
	if ((n % 4 == 0) && (n % 100 != 0) || (n % 400 == 0))
		return 1;
	else
		return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	year(n);
	if ((year(n)) == 1)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}
#include <stdio.h>
#include <math.h>
static int is_prime(int n)
{
	for (int i = 2; i < sqrt(n); i++)
	{
		if (n % i == 0)
			return 0;
	}
		return 1;
}
int main()
{
	int n;
	while ((scanf("%d", &n)) != EOF)
	{
		is_prime(n);
		if ((is_prime(n)) == 1)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}
#include <stdio.h>
static void init(int arr[],int n)
{
	for (int i = 0; i < n; i++)
	{
		arr[i] = 0;
	}
}
static void print(int arr[], int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}
static void reverse(int arr[],int n)
{
	for (int i = 0; i<=(n-1-i); i++)
	{
		int tmp = 0;
		tmp = arr[i];
		arr[i] = arr[n - 1 - i];
		arr[n - 1 - i] = tmp;
	}
}
int main()
{
	int arr[10];
	init(arr,10);
	for (int i = 0; i < 10; i++)
	{
		scanf("%d", &arr[i]);
	}
	print(arr, 10);
	reverse(arr, 10);
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}
#include "MineSweeper.h"//扫雷在这里项目不对，重新创了一个新项目


void game()
{
	char mine[ROWS][COLS];//存放雷
	char show[ROWS][COLS];//存放排查出雷的信息
	//初始化棋盘为
	//mine棋盘为'0'
	//show棋盘为'*'
	InitBoard(mine, ROWS, COLS, '0');
	InitBoard(show, ROWS, COLS, '*');
	//打印棋盘
	///DisplayBoard(show,ROW,COL);
	DisplayBoard(show, ROW, COL);
	//布置雷
	SetMine(mine,ROW, COL);
	//排查雷
	FindMine(mine, show, ROW, COL);
}
void menu()
{
	printf("*************************\n");
	printf("******** 1.play *********\n");
	printf("******** 0.exit *********\n");
	printf("*************************\n");
}
void test()
{
	srand((unsigned int)time(NULL));
	int input;
	do
	{
		menu();
		printf("请选择:>");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			printf("----开始扫雷----\n");
			game();
			break;
		case 0:
			printf("退出游戏\n");
			break;
		default:
			printf("输入错误，请重新输入\n");
			break;
		}
	} while (input);
	return;
}
int main()
{
	test();
	return 0;
}
#include <stdio.h>
int main()
{
	int a = 3;
	int b = 6;
	int c = 12;
	int m = (a, b, ++c);//逗号运算符优先级最低，++优先
	printf("m = %d,c = %d\n", m,c);
	return 0;
}
#include <stdio.h>//使二维数组左下角*n
#include <stdlib.h>
#define N 5
void fun(int a[][N], int n)
{
	int i = 0;
	for (i = 0; i < N; i++)
	{
		int j = 0;
		for (j = 0; j <= i; j++)
		{
			a[i][j] *= n;
		}
	}
}
int main()
{
	int a[N][N], n, i, j;
	printf(" * * * * * The array * * * * * \n");
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < N; j++)
		{
			a[i][j] = rand() % 10;
			printf(" %4d", a[i][j]);
		}
		printf("\n");
	}
	do n = rand() % 10;
	while (n >= 3);
		printf("n = %4d\n", n);
		fun(a, n);
		printf(" * * * * * THE RESULT * * * * * \n");
		for (i = 0; i < N;i++)
		{
			for (j = 0; j < N; j++)
			{
				printf(" %4d", a[i][j]);
			}
			printf("\n");
		}
		return 0;
}
#include <stdio.h>
void change(char str[],int sz)
{
	for (int i = 0; i < sz; i++)
	{
		if (str[i] > 'Z')
		{
			str[i] -= 32;
		}
	}
	printf(" * * * * *   End   * * * * * \n");
}
int main()
{
	char str[40];
	printf(" * * * * *  Begin  * * * * * \n");
	gets(str);
	int sz = sizeof(str) / sizeof(str[0]);
	change(str,sz);
	puts(str);
	return 0;
}
#include <stdio.h>
void change(char str[],int sz)
{
	for (int i = 0; i < sz; i++)
	{
		if (str[i] > 'Z')
		{
			str[i] -= 32;
		}
	}
}
int main()
{
	char str[40];
	gets(str);
	int sz = sizeof(str) / sizeof(str[0]);
	change(str,sz);
	puts(str);
	return 0;
}
#include <stdio.h>
int main()
{
	int arr[10] = { 0 };
	printf("%p\n", arr);
	printf("%p\n", arr+1);//跳4个字节
	printf("-----------\n");
	printf("%p\n", &arr);
	printf("%p\n", &arr+1);//跳10*4个字节
	return 0;
}
#include <stdio.h>
int main()
{
	char arr[20] = {'a','b','c','d'};//或者"abcd"
	printf("%s", arr);//记住这是%s
	return 0;
}
#include <stdio.h>
#define M 4
#define N 5
int fun(int a[M][N])
{
	int sum1 = 0;
	int sum2 = 0;
	for (int i = 0; i < M; i++)
	{
		sum1 += (a[i][0]+a[i][N-1]);
	}
	for (int j = 1; j < N-1; j++)
	{
		sum2 += (a[0][j] + a[M - 1][j]);
	}
	return sum1 + sum2;
}
int main()
{
	int aa[M][N] = { {1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0} };
	int i, j, y;
	printf("The original data is :>\n");
	for (i = 0; i < M; i++)
	{
		for (j = 0; j < N; j++)
		{
			printf("%6d", aa[i][j]);
		}
		printf("\n");
	}
	y = fun(aa);
	printf("\nThe sum:>%d\n", y);
	printf("\n");
	return 0;
}
#include <stdio.h>//输入CEAedca，中间5个按ASCII值降序排列
//void fun(char* s, int num)
//{
//	int i = 0;
//	for(i = 0;i<num-2;i++)
//	{
//		int count = 0;
//		int j = 0;
//		char tmp;
//		for (j = 1; j < num -1-i; j++)
//		{
//			if ( * (s + j) <  * (s + j + 1))
//			{
//				tmp = *(s + j);
//				*(s + j) = *(s + j + 1);
//				*(s + j) = tmp;
//				count = 1;
//			}
//		}
//		if (count == 0)
//		{
//			break;
//		}
//	}
//}
void fun(char* s, int num)
{
	char t;
	int i, j;
	for (i = 1; i < num - 2; i++)
	{
		for (j = i + 1; j < num - 1; j++)
		{
			if (s[i] < s[j])
			{
				t = s[i];
				s[i] = s[j];
				s[j] = t;
			}
		}
	}
}
int main()
{
	char s[10];
	printf("输入7个字符的字符串:>");
	gets(s);
	fun(s, 7);
	printf("\n%s", s);
	return 0;
}
#include <stdio.h>//冒泡排序
int main()
{
	int i = 0;
	int j = 0;
	int t = 0;
	int arr[10] = { 2,4,8,5,7,3,1,6,5,10 };//成升序
	int sz = sizeof(arr) / sizeof(arr[0]);
	for (i = 0; i < sz - 1; i++)//趟数
	{
		for (j = 0; j < sz - 1 - i;j++)
		{
			if (arr[j] > arr[j + 1])
			{
				t = arr[j + 1];
				arr[j + 1] = arr[j];
				arr[j] = t;
			}
		}
	}
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}

#include <stdio.h>//冒泡排序进阶
static void Swap(char* e1, char* e2, int width)
{
	for (int i = 0; i < width; i++)
	{
		char tmp = *e1;
		*e1 = *e2;
		*e2 = tmp;
		e1++;
		e2++;
	}
}
static int cmp_int(const void* e1, const void* e2)//这里好像也能写const char* e1
{
	return(*(int*)e1 - *(int*)e2);
}
static void bubble_sort(void* base, int sz, int width, int(*cmp)(const void* e1, const void* e2))
{
	int i = 0;
	int j = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int flag = 1;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width)>0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
				flag = 0;
			}
		}
		if (flag == 1)
		{
			break;
		}
	}
}
int main()
{
	int arr[] = { 10,9,8,7,6,5,4,3,2,1,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz,sizeof(arr[0]),cmp_int);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}
#include <stdio.h>//动态内存管理
#include <stdlib.h>//malloc,calloc,realloc,free
#include <errno.h>//errno
#include <string.h>//strerror
int main()
{
	int i = 0;

	//malloc
	//int* p = (int*)malloc(40);//INT_MAX，malloc不会初始化，除了初始化，基本和calloc相同
	// calloc=(malloc+memset)开辟加初始化
	//if (p == NULL)
	//{
	//	printf("%s\n", strerror(errno));
	//	return 1;
	//}
	//for (i = 0; i < 10; i++)
	//{
	//	*(p + i) = i;
	//	printf("%d ", *(p + i));
	//}

	//calloc
	//int* p = (int*)calloc(10, sizeof(int));//calloc会初始化
	//if (p == NULL)
	//{
	//	printf("%s", strerror(errno));
	//	return 1;//异常返回
	//}
	//for (i = 0; i < 10; i++)
	//{
	//	printf("%d ", *(p + i));
	//}

	//realloc
	int* p = (int*)malloc(40);
	if (p == NULL)
	{
		printf("%s\n", strerror(errno));//=perror("p");
		return 1;
	}
	for (i = 0; i < 10; i++)
	{
		*(p + i) = i+1;
		printf("%d ", *(p + i));
	}
	printf("\n");
	//realloc(NULL,40) = malloc(40)
	int* ptr = (int*)realloc(p, 80);//为什么不int* p = (int*)realloc(p, 80);???
	if (ptr != NULL)
	{
		p = ptr;//情况一，旧地址回收，情况二，在原地址向后申请空间
		//地址是一样的,释放p就是释放ptr
	}
	else
	    return 1;
	for (i = 0; i < 20; i++)
	{
		*(p + i) = i + 1;
		printf("%d ", *(p + i));
	}
	free(p);
	p = NULL;//更安全//既然用了ptr，为什么不写ptr = NULL???
	return 0;
}
#include <stdio.h>
void f(int* a, int* b)
{
	int t;
	t = *a;
	*a = *b;
	*b = t;
}
int main()
{
	int i = 3;
	int j = 6;
	f(&i, &j);
	printf("%d %d", i, j);
	return 0;
}
#include <stdio.h>
int main()
{
	char arr[] = "abc";//4
	int sz = sizeof(arr) / sizeof(arr[0]);
	printf("%d\n", sz);
	char x[3][4];
	int i = 0;
	for (i = 0; i < 3; i++)
	{
		strcpy(x[i], arr);
		printf("%s", &x[i][i]);//abcbcc
		//printf("%c", x[i][i]);//abc
	}
	return 0;
}
#include <stdio.h>//n = k*k,n中有两位数字相同
int flag(int x, int y, int z)
{
	return(!((x - y) * (x - z) * (y - z)));
}
int main()
{
	int n, k,a,b,c;
	for (k = 1;; k++)
	{
		n = k * k;
		if (n < 100)continue;
		if (n > 999)break;
		a = n / 100;
		b = n / 10 % 10;
		c = n % 10;
		if(flag(a,b,c))
		printf("n = %d = %d*%d\n", n, k, k);
	}
	return 0;
}
#include <stdio.h>//e的近似值
#define nmax 20
float f2(int n)
{
	if (n == 1) return 1;
	else return n * f2(n - 1);
	//else return n * f2(--n);//错
}
float f1(float x, int n)
{
	int i = 0;
	float j = 1;
	for (i = 1; i <= n; i++)j *= x;
	return j;
}
int main()
{
	float x, exp = 1.0; int n;
	scanf("%f", &x);
	for (n = 1; n < nmax; n++)
	{
		exp = exp + f1(x, n) / f2(n);
	}
	printf("x = %f,exp(x) = %f\n", x, exp);
	return 0;
}
#include <stdio.h>//行地址解引用为该行的第一个值
int main()
{
	int arr[2][3] = { 1,2,3,4,5,6 };
	printf("%d\n", *(arr[0]));//行地址解引用为该行的第一个值
	printf("%d\n", arr[0][0]);
	return 0;
}
#include <stdio.h>
int main()
{
	char arr[] = "a";
	char* p = arr;
	p++;
	int flag = 0;
	for (; *p;)//'\0',0,*p都为假进不去
	{
		flag = 1;
	}
	printf("%d\n", flag);
	return 0;
}
#include <stdio.h>
int main()
{
	int count = 0;
	int i = 0;
	int sum = 0;
	for (i = 20; i >= 1; i/=2)
	{
		sum += i;
	}
	printf("%d\n", sum+1);
	return 0;
}
#include <stdio.h>//菱形，n为奇数
int main()
{
	int i = 0;
	int j = 0;
	int n = 0;
	scanf("%d", &n);
	for (j = 1; j <= (n + 1) / 2; j++)
	{
		for (i = 0; i < (n + 1 - 2 * j) / 2; i++)
		{
			printf(" ");
		}
		for (i = 0; i < (2 * j - 1); i++)
		{
			printf("*");
		}
		printf("\n");
	}
	for (j = (n - 1) / 2; j >= 1; j--)
	{
		for (i = 0; i < (n + 1 - 2 * j) / 2; i++)
		{
			printf(" ");
		}
		for (i = 0; i < (2 * j - 1); i++)
		{
			printf("*");
		}
		printf("\n");
	}
	return 0;
}
#include <stdio.h>//水仙花数
#include <math.h>
int main()
{
	int i = 0;
	int j = 0;
	int n = 0;
	int count = 0;
	int arr[6] = { 0 };//用来存放各个位数的值
	for (i = 1; i < 100000; i++)
	{
		int sum = 0;//每次重置sum为0
		for (n = 1; ;n++)//n位数
		{
			if (i / (int)pow(10 , n) == 0)
			{
				break;
			}
		}
		for (j = 0; j < n; j++)//得到各个位数存放到arr里
		{
			arr[j] = i / (int)pow(10 , j) % 10;
			sum += (int)pow(arr[j] , n);

		}
		if (i == sum)
		{
			count++;
			printf("%d\n", i);
		}
	}
	printf("共有%d个水仙花数", count);
	return 0;
}
#include <stdio.h>//Sn=a+aa+aaa+aaaa+aaaaa
#include <math.h>
int main()
{
	int a = 0;
	scanf("%d", &a);
	int sum = a;
	int b = a;
	int i = 0;
	for (i = 1; i < 5; i++)
	{
		b += a * pow(10, i);
		sum += b;
	}
	printf("%d", sum);
	return 0;
}
#include <stdio.h>//递归  斐波那契数列
int fun(int n)
{
	if (n < 3)
		return 1;
	else
		return fun(n - 1) + fun(n - 2);
}
int main()
{
	int n = 0;
	printf("please input n :>\n");
	while (scanf("%d", &n) != EOF)
	{
		int ret = fun(n);
		printf("%d\n", ret);
	}
	return 0;
}
#include <stdio.h>//非递归  斐波那契数列
int main()
{
	int n = 0;
	printf("please input n :>\n");
	while (scanf("%d", &n) != EOF)
	{
		int a = 1;
		int b = 1;
		int c = 2;
		if (n < 3)
		{
			printf("1\n");
		}
		else
		{
			while (n > 3)
			{
				a = b;
				b = c;
				c = a + b;
				n--;
			}
			printf("%d\n", c);
		}
	}
	return 0;
}
#include <stdio.h>//n的k次方
int test(int n,int k)
{
	if (k == 1)
	{
		return n;
	}
	else
		return n * test(n, k - 1);
}
int main()
{
	int n, k;
	while (scanf("%d%d", &n, &k) != EOF)
	{
		int ret = test(n, k);
		printf("%d\n", ret);
	}
	return 0;
}
#include <stdio.h>//递归   返回各个位数相加的和
int DigitSum(int n,int sum)
{
	if (n == 0)
		return sum;
	int m = n % 10;
	return DigitSum(n / 10, sum + m);
}
int main()
{
	int n = 0;
	int sum = 0;
	scanf("%d", &n);
	int ret = DigitSum(n,sum);
	printf("%d\n", ret);
	return 0;
}

#include <stdio.h>//递归   n的阶层
int fun(int n)
{
	if (n == 1)
		return 1;
	else
		return n * fun(n - 1);
}
int main()
{
	int n;
	scanf("%d", &n);
	int ret = fun(n);
	printf("%d\n", ret);
	return 0;
}
#include <stdio.h>//非递归   n的阶层
int main()
{
	int n,i;
	int m = 1;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		m *= i;
	printf("%d", m);
	return 0;
}
#include <stdio.h>//递归 打印每一位
void Print(int n)
{
	if (n > 9)
		Print(n / 10);
	printf("%d ", n % 10);
}
int main()
{
	int n;
	scanf("%d", &n);
	Print(n);
	return 0;
}
#include <stdio.h>//交换两个变量（不创建临时变量）
int main()
{
	int a = 3;
	int b = 6;
	a = a ^ b;
	b = a ^ b;
	a = a ^ b;
	printf("%d %d", a, b);
	return 0;
}
#include <stdio.h>//统计二进制中1的个数
int main()
{
	int n;
	scanf("%d", &n);
	int count = 0;
	while (n)
	{
		n &= n - 1;
		count++;
	}
	printf("%d", count);
	return 0;
}
#include <stdio.h>//求两个数二进制中不同位的个数
int main()
{
	int m = 1999;
	int n = 2299;
	int a = m ^ n;
	int count = 0;
	while (a)
	{
		a &= a - 1;
		count++;
	}
	printf("%d", count);
	return 0;
}
#include <stdio.h>//找单生狗，我这有点问题
int main()
{
	int arr[] = {1,2,3,4,5,1,2,3,4};
	int i = 0;
	int j = 0;
	int a = 0;
	int sz = sizeof(arr) / sizeof(arr[0]);
	for (i = 0; i < sz; i++)
	{
		for (j = i; j < sz-1; j++)
		{
			if (arr[i] == arr[j+1])
				break;
		}
		if (j==sz-1)
		{
			printf("%d\n", arr[i]);
			return 0;
		}
	}
	return 0;
}
#include <stdio.h>
int main()
{
	int i = 0;
	int n;
	scanf("%d", &n);
	for (i = 30; i >= 0; i-=2)//奇
	{
		if ((n & (1 <<i)) == 0)
			printf("0");
		else
			printf("1");
	}
	printf(" 奇\n");
	for (i = 31; i >=1; i -= 2)//偶
	{
		if ((n & (1 << i)) == 0)
			printf("0");
		else
			printf("1");
	}
	printf(" 偶\n");
	return 0;
}
#include <stdio.h>//字符串逆序
void test(char* a,int sz)
{
	int i = 0;
	for (i = 0; i < sz-i-1; i++)
	{
		char tmp = *(a+i);
		*(a + i) = *(a + sz - i - 1);
		*(a + sz - i - 1) = tmp;
	}
	for (i = 0; i < sz; i++)
	{
		printf("%c", a[i]);
	}
}
int main()
{
	char a[] = "I am a student";
	int sz = sizeof(a) / sizeof(a[0]);
	test(a,sz);
	return 0;
}
#include <stdio.h>//实现一个函数，可以左旋字符串中的k个字符。



例如：



ABCD左旋一个字符得到BCDA

ABCD左旋两个字符得到CDAB
void func(char arr[], int sz, int k)
{
	int i = 0;
	for (i = 0; i < k; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 2; j++)
		{
			char tmp = arr[j];
			arr[j] = arr[j + 1];
			arr[j + 1] = tmp;
		}
	}
	printf("%s", arr);
}
int main()
{
	char arr[] = "ABCDEF";
	int k;
	scanf("%d", &k);
	int sz = sizeof(arr) / sizeof(arr[0]);
	func(arr, sz, k);
	return 0;
}
#include <stdio.h>//模拟srtlen
int strlen(char arr[])
{
	int count = 0;
	while (*(arr++))
	{
		count++;
	}
	return count;
}
int main()
{
	char arr[] = "abcdef";
	int slen = strlen(arr);
	printf("%d\n", slen);
	return 0;
}
#include <stdio.h>
int main()
{
	int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int* p = arr;
	for (int i = 0; i < 10; i++)
	{
		printf("%d ", *(p + i));
	}
	return 0;
}
#include <stdio.h>//冒泡排序
void Func(int arr[], int sz)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < sz - 1; i++)
	{
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				int tmp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = tmp;
			}
		}
	}
}
void Print(int arr[], int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}
int main()
{
	int arr[10] = { 3,2,5,9,7,8,4,1,6,10 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	Func(arr,sz);
	Print(arr,sz);
	return 0;
}
#include <stdio.h>//猜凶手
int main()
{
	char killer = 0;
	for (killer = 'a'; killer <= 'd'; killer++)
	{
		if ((killer != 'a') + (killer == 'c') + (killer == 'd') + (killer != 'd') == 3)
		{
			printf("凶手是%c", killer);
		}
	}
	return 0;
}
#include <stdio.h>//杨辉三角
void Func(int arr[][100], int n)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < n; i++)//行
	{
		for (j = 0; j < i + 1; j++)//列
		{
			if ((i == j)||(j==0))
				arr[i][j] = 1;
			else
				arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
		}

	}
}
void Print(int arr[][100], int n)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < i+1; j++)
		{
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
}
int main()
{
	int arr[100][100] = { 0 };
	int n;
	scanf("%d", &n);
	Func(arr, n);
	Print(arr, n);
	return 0;
}
#include <stdio.h>//判断一个字符串是否为另外一个字符串旋转之后的字符串。
#include <string.h>
int Func(char m[],char n[])
{
	char tmp[100] = { 0 };
	strcat(tmp, m);
	strcat(tmp, m);
	return strstr(tmp, n) != NULL;
}
int main()
{
	char m[100];
	char n[100];
	gets(m);
	gets(n);
 	int ret = Func(m, n);
	if (ret == 1)
	{
		printf("是旋转后的结果\n");
	}
	else
		printf("不是旋转后的结果\n");
	return 0;
}
#include <stdio.h>//杨氏矩阵找数
int Func(int arr[][3], int x, int y, int k)
{
	int i = 0;
	int j = y-1;
	while ((i < x) && (j >= 0))
	{
		if (k > arr[i][j])
		{
			i++;
		}
		else if (k < arr[i][j])
		{
			j--;
		}
		else
		{
			return 1;
		}
	}
	return 0;
}
int main()
{
	int k;
	scanf("%d", &k);
	int arr[3][3] = { {1,2,3} ,{ 4,5,6 } ,{ 7,8,9 } };
	int ret = Func(arr, 3, 3, k);
	if (ret == 1)
	{
		printf("找到了\n");
	}
	else
		printf("找不到\n");
	return 0;
}
#include <stdio.h>//单身狗2
int Find1(int arr[], int sz, int a)
{
	int k = 1;
	while (1)
	{
		if ((a & 1) == 1)
		{
			break;
		}
		a >>= 1;
		k++;
	}
	return k;
}
void FindDog(int arr[], int sz, int k,int a)
{
	int b = 0;
	int c = 0;
	while (sz > 0)
	{
		if (((arr[sz - 1]) & (1<<(k-1))) == 1)
		{
			b ^= arr[sz - 1];
		}
		else
			c ^= arr[sz - 1];
		sz--;
	}
	printf("Dogs are %d,%d", a ^ b, a ^ c);
}
int main()
{
	int arr[10] = { 0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		scanf("%d", &arr[i]);
	}
	int a = 0;
	for (int i = 0; i < sz; i++)
	{
		a ^= arr[i];
	}
	int ret = Find1(arr, sz, a);
	FindDog(arr, sz, ret, a);
	return 0;
}
#include <stdio.h>//某年某月的天数
int  Func(int arr[], int year, int month)
{
	if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
	{
		if (month == 2)
			return arr[0];
	}
	return arr[month];
}
int main()
{
	int year, month;
	while (scanf("%d %d", &year, &month) != EOF)
	{
		int arr[] = { 29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		int Day = Func(arr, year, month);
		printf("%d\n", Day);
	}
	return 0;
}
#include <stdio.h>//while(n--)先判断n真假，再自减，打印,
int main()
{
	int n = 5;
	while (n--)
	{
		printf("%d ", n);
	}
	return 0;
}

#include <stdio.h>//转移表--函数指针数组--简易计算机
int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}
int mul(int a,int b)
{
	return a * b;
}
int div(int a, int b)
{
	return a / b;
}
void menu()
{
	printf("******* 1.add  2.sub *******\n");
	printf("******* 3.mul  4.div *******\n");
	printf("******* 0.exit       *******\n");

}

int main()
{
	int a, b, c;
	int input = 0;
	int (*p[5])(int a, int b) = { 0,add,sub,mul,div };
	do
	{
		menu();
		printf("请输入:>\n");
		scanf("%d", &input);
		if (input >= 1 && input <= 4)
		{
			printf("请输入操作数:>\n");
			scanf("%d%d", &a, &b);
			c = p[input](a, b);
			printf("%d\n", c);
		}
		else if (input == 0)
		{
			printf("退出计算机\n");
		}
		else
		{
			printf("输入错误，请重新输入\n");
		}
	} while (input);
	return 0;
}
#include <stdio.h>//冒泡排序
void bubble(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)//sz-1趟
	{
		int j = 0;
		int flag = 1;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				int tmp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = tmp;
				flag = 0;
			}
		}
		if (flag == 0)
			break;
	}
}
void Print(int arr[], int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
}
int main()
{
	int arr[] = { 3,2,1,4,7,6,5,9,8 ,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble(arr, sz);
	Print(arr, sz);
	return 0;
}
#include <stdio.h>//冒泡排序简单实现qsort
#include <string.h>

void Swap(char* e1, char* e2, int width)//交换
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = e1[i];
		e1[i] = e2[i];
		e2[i] = tmp;
	}
}
//void Swap(char* e1, char* e2, int width)
//{
//	int i = 0;
//	for (i = 0; i < width; i++)
//	{
//		char tmp = *e1;
//		*e1 = *e2;
//		*e2 = tmp;
//		e1++;
//		e2++;
//	}
//}
int cmp_int(const char* a, const char* b)//比较int
{
	return *(int*)a - *(int*)b;
}

struct Stu
{
	char name[20];
	int age;
};

int cmp_Stu_by_name(const char* a,const char* b)//比较结构体中的name,const防止别人改
{
	return strlen(a) - strlen(b);
}

int cmp_Stu_by_age(const char* a, const char* b)//比较结构体中的age，本来想和cmp_int和起来，但return后面的不一样
{
	return ((struct Stu*)a)->age - ((struct Stu*)b)->age;//强制类型转换成结构体类型，加()先执行
}

void bubble_sort(void* base,int sz, int width, int(*cmp)(void*,void* ))//bubble_sort
{
	int i = 0;
	for (i = 0; i < sz; i++)//趟不变
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base+j*width,(char*)base+(j+1)*width)>0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}

void test3()
{
	struct Stu arr[3] = { {"abczhangsan",20},{"abclisi",50},{"abcwangwu",25} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_Stu_by_name);
}
void test2()
{
	struct Stu arr[3] = { {"zhangsan",20},{"lisi",50},{"wangwu",25} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_Stu_by_age);
}

void test1()
{
	int arr[] = { 3,2,5,4,7,6,8,0,9,1 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_int);
}

int main()
{
	test1();
	//test2();//调试看arr箭头就要指向arr
	//test3();
	return 0;
}
#include <stdio.h>//qsort排序各种类型的数据
#include <string.h>
#include <stdlib.h>

int cmp_int(const char* a, const char* b)//比较int
{
	return *(int*)a - *(int*)b;
}

struct Stu
{
	char name[20];
	int age;
};

int cmp_Stu_by_name(const char* a, const char* b)//比较结构体中的name,const防止别人改
{
	return strlen(a) - strlen(b);
}

int cmp_Stu_by_age(const char* a, const char* b)//比较结构体中的age，本来想和cmp_int和起来，但return后面的不一样
{
	return ((struct Stu*)a)->age - ((struct Stu*)b)->age;//强制类型转换成结构体类型，加()先执行
}


void test3()
{
	struct Stu arr[3] = { {"abczhangsan",20},{"abclisi",50},{"abcwangwu",25} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_Stu_by_name);
}
void test2()
{
	struct Stu arr[3] = { {"zhangsan",20},{"lisi",50},{"wangwu",25} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_Stu_by_age);
}

void test1()
{
	int arr[] = { 3,2,5,4,7,6,8,0,9,1 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_int);
}

int main()
{
	//test1();
	//test2();
	test3();
	return 0;
}
#include <stdio.h>//枚举类型

enum weekday { sun, mon, tue, wed, thu, fri, sat } workday,week_end;//变量名

int main()
{
	workday = (enum weekday)2;//实际上workday = mon
	return 0;
}

#include <stdio.h>//calloc初始化为0
#include <stdlib.h>//malloc,calloc,realloc,free
#include <errno.h>//errno
#include <string.h>//strerror

int main()
{
	int i = 0;
	int* p = (int*)calloc(10, sizeof(int));//calloc会初始化,感觉一直用它就行，都不用malloc
	if (p == NULL)
	{
		printf("%s", strerror(errno));
		return 1;//异常返回
	}
	for (i = 0; i < 10; i++)
	{
		printf("%d ", *(p + i));
	}
	return 0;
}
#include <stdio.h>//strlen模拟实现
#include <assert.h>

int My_Strlen(char* a)//指针
{
	assert(a);
	char* p = a;
	while (*p != '\0')
	{
		p++;
	}
	return p-a;
}

//int My_Strlen( const char* a)//递归
//{
//  assert(a);
//	if (*a == '\0')
//	{
//		return 0;
//	}
//	else
//		return 1 + My_Strlen(a + 1);
//}

//int My_Strlen( const char* a)//常规
//{
//	assert(a);
//	int count = 0;
//	int i = 0;
//	while (*(a+i) != '\0')
//	{
//		count++;
//		i++;
//	}
//	return count;
//}

int main()
{
	char arr[] = "abcdef";
	int ret = My_Strlen(arr);
	printf("%d\n", ret);
	return 0;
}

#include <stdio.h>//strcpy模拟实现

void My_Strcpy(char* arr1,const char* arr2)
{
	while (*arr1++ = *arr2++)
	{
		;
	}
}

int main()
{
	char arr1[20] = { 0 };
	char arr2[] = "abcdef";
	My_Strcpy(arr1,arr2);
	printf("%s\n", arr1);
	printf("%s\n", arr2);
	return 0;
}

#include <stdio.h>

struct//这种结构体定义(其实已经创建变量了)要在这里初始化
{
	char name[20];
	int age;
}SqList = { "abc",10 };

int main()
{
	printf("%s %d\n", SqList.name, SqList.age);
	return 0;
}

//struct SqList
//{
//	char name[20];
//	int age;
//}L;
//
//
//int main()
//{
//	struct SqList L ={ "abc",10 };
//	printf("%s %d", L.name, L.age);
//	return 0;
//}

#include <stdio.h>//模拟实现strcat
#include <assert.h>

char* My_Strcat(char* arr1, const char* arr2)
{
	assert(arr1 && arr2);
	char* ret = arr1;
	//while (*arr1++ != '\0')//向后多走了一位
	//{
	//	;
	//}
	while (*arr1 != '\0')
	{
		arr1++;
	}
	while (*arr1++ = *arr2++)
	{
		;
	}
	return ret;
}

int main()
{
	char arr1[20] = "Hello ";
	char arr2[] = "bit";
	char* ret = My_Strcat(arr1, arr2);
	printf("%s\n", ret);
	printf("%s\n", arr1);
	return 0;
}

#include <stdio.h>//设计一个从三个整数类型数据中得到最大数值和次大数值的函数

void Max2(int a,int b,int c,int* max1,int* max2)
{
	int tmp = 0;
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	if (a < c)
	{
		tmp = a;
		a = c;
		c = tmp;
	}
	if (b < c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	*max1 = a;
	if (b > c)
		*max2 = b;
	else
		*max2 = c;
}

int main()
{
	int a = 6, b = 7, c = 8;
	int max1 = 0;
	int max2 = 0;
	Max2(a, b, c, &max1, &max2);
	printf("%d %d\n", max1, max2);
	return 0;
}

#include <stdio.h>//模拟strcmp
#include <assert.h>

int My_Strcmp(const char* arr1, const char* arr2)
{
	assert(arr1 && arr2);
	while (*arr1 == *arr2)
	{
		if (*arr1 == '\0')
			return 0;
		arr1++;
		arr2++;
	}
	if (*arr1 > *arr2)
		return 1;
	else
		return -1;
}

int main()
{
	char arr1[] = "abcd";
	char arr2[] = "abce";
	int ret = My_Strcmp(arr1,arr2);
	if (ret == 1)
		printf("arr1 大于 arr2\n");
	else if (ret == -1)
		printf("arr1 小于 arr2\n");
	else
		printf("arr1 等于 arr2\n");
	return 0;
}

#include <stdio.h>//模拟strstr
#include <assert.h>
char* My_Strstr(const char* str1, const char* str2)
{
	assert(str1 && str2);
	const char* a = NULL;
	const char* b = NULL;
	const char* c = str1;
	if (*str2 == '\0')
		return (char*)str1;
	while (*c)
	{
		a = c;
		b = str2;
		while (*a!='\0'&& *a == *b && *b!='\0')
		{
			a++;
			b++;
		}
		if (*b == '\0')
		{
			return (char*)c;
		}
		c++;
	}
	return NULL;
}

int main()
{
	char arr1[] = "abcdef";
	char arr2[] = "c";
	char* ret = My_Strstr(arr1, arr2);
	if (ret == NULL)
		printf("找不到\n");
	else
		printf("%s\n", ret);
	return 0;
}

#include <stdio.h>//模拟实现strncpy

char* My_Strncpy(char* dest, const char* source, size_t num)
{
	char* start = dest;
	while (num--)
	{
		if (*source != '\0')
			*dest++ = *source++;
		else
			*dest++ = '\0';
	}
	return start;
}

int main()
{
	char arr1[7] = "abcdef";
	arr1[3] = '\0';//如果之前就是\0调试就不会变红了
	char arr2[] = "cf";
	My_Strncpy(arr1, arr2, 6);
	printf("%s\n", arr1);
	return 0;
}

#include <stdio.h>//模拟strncat,如果之前就是\0调试就不会变红了，所以没问题

char* My_Strncat(char* arr1, const char* arr2, size_t num)
{
	char* ret= arr1;
	while (*arr1 != '\0')
	{
		arr1++;
	}
	while (num--)
	{
		*arr1 = *arr2;
		arr1++;
		arr2++;
		if (*arr2 == '\0')
			break;
	}
	*arr1 = '\0';
	return ret;
}

int main()
{
	char arr1[10] = "abc";
	char arr2[] = "def";
	My_Strncat(arr1, arr2, 2);
	printf("%s\n", arr1);
	return 0;
}

#include <stdio.h>//移位运算符不一定是左乘右除
int main()
{
	int b = -20;
	printf("%d\n", b >> 3);
	return 0;
}

#include <stdio.h>//模拟memcpy   num代表字节数
#include <assert.h>

void* My_Memcpy(void* dest, const void* source, size_t num)
{
	assert(dest && source);
	void* ret = dest;
	while (num--)
	{
		*((char*)dest) = *((char*)source);
		dest = (char*)dest + 1;
		source = (char*)source + 1;
	}
	return ret;
}

int main()
{
	int arr1[] = {1,2,3,4,5,6,7,8,9,10};
	int arr2[10] = {0};
	My_Memcpy(arr2, arr1, 20);
	for (int i = 0; i < 10; i++)
	{
		printf("%d\n", arr2[i]);
	}
	return 0;
}

#include <stdio.h>//模拟memmove，num表示字节数
#include <assert.h>
void* My_Memmove(void* dest, const void* source, size_t num)
{
	assert(dest && source);
	void* ret = dest;
	if (dest < source||(char*)dest>=(char*)source+num)
	{
		while (num--)
		{
			*(char*)dest = *(char*)source;
			dest = (char*)dest + 1;
			source = (char*)source + 1;
		}
	}
	else
	{
		//dest = (char*)dest + num - 1;
		//source = (char*)source + num - 1;
		//while (num--)
		//{
		//	*(char*)dest = *(char*)source;
		//	dest = (char*)dest - 1;
		//	source = (char*)source - 1;
		//}
		while (num--)
		{
			*((char*)dest + num) = *((char*)source + num);
		}
	}
	return ret;
}

int main()
{
	int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };
	//My_Memmove(arr1, arr1 + 2, 16);//3456 56 78910
	//My_Memmove(arr1 + 3, arr1 + 2, 16);//123 3456 8910
	My_Memmove(arr1 + 2, arr1, 16);//12 1234 78910  //我应该进去调试的，难受

	return 0;
}

#include <stdio.h>//博客案例
int main()
{
	int n = 5;
	while (--n)
	{
		printf("%d\n", n);
	}
	return 0;
}

#include <stdio.h>
int main()
{
	int n = 5;
	while (n--)
	{
		printf("%d\n", n);
	}
	return 0;
}

#include <stdio.h>
int main()
{
	int n = 5;
	while (n--)
	{
		循环体
	}
	return 0;
}

#include <stdio.h>
int main()
{
	int arr[] = { 1,2,3,4,5 };
	printf("%zd\n", sizeof(&arr));//8
	printf("%zd\n", sizeof(arr));//20
	return 0;
}

#include <stdio.h>//博客案例
int main()
{
	char str1[] = "hello bit.";
	char str2[] = "hello bit.";
	const char* str3 = "hello bit.";
	const char* str4 = "hello bit.";
	if (str1 == str2)
		printf("str1 and str2 are same\n");
	else
		printf("str1 and str2 are not same\n");
	if (str3 == str4)
		printf("str3 and str4 are same\n");
	else
		printf("str3 and str4 are not same\n");
	return 0;
}

#include <stdio.h>
void test(int a[3][5], int r, int c)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			printf("%d ", a[i][j]);
		}
		printf("\n");
	}
}
int main()
{
	int arr[3][5] = { {1,2,3,4,5}, {2,3,4,5,6},{3,4,5,6,7} };
	test(arr, 3, 5);
	return 0;
}

#include <stdio.h>
void test(int(*p)[5], int r, int c)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			printf("%d ", *(*(p + i) + j));
		}
		printf("\n");
	}
}
int main()
{
	int arr[3][5] = { {1,2,3,4,5}, {2,3,4,5,6},{3,4,5,6,7} };
	test(arr, 3, 5);
	return 0;
}

#include <stdio.h>
void test()
{
	printf("hehe\n");
}
int main()
{
	printf("test: %p\n", test);
	printf("&test: %p\n", &test);
	return 0;
}

#include <stdio.h>//计算器的一般实现
int Add(int x, int y)
{
	return x + y;
}
int main()
{
	int(*pf3)(int, int) = Add;
	printf("%d\n", (*pf3)(2, 3));
	printf("%d\n", pf3(3, 5));//pf = add,既然可以add(3,5),那也可以pf(3,5),所以有没有*无所谓
	return 0;
}

#include <stdio.h>//计算器的一般实现
int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}
int mul(int a, int b)
{
	return a * b;
}
int div(int a, int b)
{
	return a / b;
}
int main()
{
	int x, y;
	int input = 1;
	int ret = 0;
	do
	{
		printf("*************************\n");
		printf(" 1:add 2:sub \n");
		printf(" 3:mul 4:div \n");
		printf(" 0:exit \n");
		printf("*************************\n");
		printf("请选择：");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			printf("输入操作数：");
			scanf("%d %d", &x, &y);
			ret = add(x, y);
			printf("ret = %d\n", ret);
			break;
		case 2:
			printf("输入操作数：");
			scanf("%d %d", &x, &y);
			ret = sub(x, y);
			printf("ret = %d\n", ret);
			break;
		case 3:
			printf("输入操作数：");
			scanf("%d %d", &x, &y);
			ret = mul(x, y);
			printf("ret = %d\n", ret);
			break;
		case 4:
			printf("输入操作数：");
			scanf("%d %d", &x, &y);
			ret = div(x, y);
			printf("ret = %d\n", ret);
			break;
		case 0:
			printf("退出程序\n");
			break;
		default:
			printf("选择错误\n");
			break;
		}
	} while (input);
	return 0;
}

#include <stdio.h>//使用函数指针数组(转移表)的实现
int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}
int mul(int a, int b)
{
	return a * b;
}
int div(int a, int b)
{
	return a / b;
}
int main()
{
	int x, y;
	int input = 1;
	int ret = 0;
	int(*p[5])(int x, int y) = { 0, add, sub, mul, div }; //转移表
	do
	{
		printf("*************************\n");
		printf(" 1:add 2:sub \n");
		printf(" 3:mul 4:div \n");
		printf(" 0:exit \n");
		printf("*************************\n");
		printf("请选择：");
		scanf("%d", &input);
		if ((input <= 4 && input >= 1))
		{
			printf("输入操作数：");
			scanf("%d %d", &x, &y);
			ret = (*p[input])(x, y);
			printf("ret = %d\n", ret);
		}
		else if (input == 0)
		{
			printf("退出计算器\n");
		}
		else
		{
			printf("输入有误\n");
		}
	} while (input);
	return 0;
}

#include <stdio.h>
int main()
{
	unsigned char a = 200;
	unsigned char b = 100;
	unsigned char c = 0;
	c = a + b;
	printf(" % d % d", a + b, c);//300,44
	return 0;
}

#include <stdio.h>//判断大小端

int check_sys(int* i)
{
	return *(char*)i;
}

int main()
{
	int i = 1;
	int ret = check_sys(&i);
	if (ret == 1)
	{
		printf("小端\n");
	}
	else
	{
		printf("大端\n");
	}
	return 0;
}

#include <stdio.h>//简单模拟实现aoti
#include <assert.h>
#include <ctype.h>//isspace 用来判断字符是否为空格/回车/制表符等 isspace()成功返回非零值 失败返回0
//isdigit函数用于判断字符是否为阿拉伯数字（0-9），返回值：0-不是数字，非0-是数字。

int My_Atoi(const char* str)
{
	int flag = 1;
	assert(str);//判断空指针
	if (*str == '\0')//判断空字符串
	{
		return 0;
	}
	while (isspace(*str))//跳过空格所在的地址
	{
		str++;
	}
	if (*str == '+')//判断正负号
	{
		flag = 1;
		str++;
	}
	else if (*str == '-')
	{
		flag = -1;
		str++;
	}
	int n = 0;
	while (*str != '\0')
	{
		if (isdigit(*str))
		{
			n = n * 10 + flag * (*str - '0');
		}
		else
			break;
			str++;
	}
	return n;
}

int main()
{
	//char* a = "";//空字符串
	char* arr = "123abd";
	int ret = My_Atoi(arr);
	printf("%d\n", ret);
	return 0;
}

#include <stdio.h>

struct S
{
	char a : 3;
	char b : 4;
	char c : 5;
	char d : 4;
};
int main()
{
	struct S s = { 0 };
	int sz = sizeof(s);
	return 0;
}

#include <stdio.h>//习题验证
#include <string.h>

int main()
{
	unsigned char puc[4];
	struct tagPIM
	{
		unsigned char ucPim1;
		unsigned char ucData0 : 1;
		unsigned char ucData1 : 2;
		unsigned char ucData2 : 3;
	}*pstPimData;
	pstPimData = (struct tagPIM*)puc;
	memset(puc, 0, 4);
	pstPimData->ucPim1 = 2;
	pstPimData->ucData0 = 3;
	pstPimData->ucData1 = 4;
	pstPimData->ucData2 = 5;
	printf("%02x %02x %02x %02x\n", puc[0], puc[1], puc[2], puc[3]);
	return 0;
}

#include <stdio.h>//使用联合体判断大小端

union Un
{
	int a;
	char b;
};

int main()
{
	union Un un;
	un.a = 1;
	if (un.b == 1)
	{
		printf("小端\n");
	}
	else
	{
		printf("大端\n");
	}
	return 0;
}
#include <stdio.h>//1461 = 1*461 + 14*61 + 146*1 求出 5位数中的所有 Lily Number。
#include <math.h>

int main() {
	int a = 10000;
	int count = 0;
	while (a < 100000)
	{
		int i = 0;
		int sum = 0;
		for (i = 4; i > 0; i--)
		{
			int b = a / (int)pow(10, i);
			int c = a - b * (int)pow(10, i);
			sum += b * c;
		}
		if (sum == a)
		{
			count++;
			printf("%d ", sum);
		}
		a++;
	}
	//printf("\n变种水仙花有%d个",count);
	return 0;
}

#include <stdio.h>//有一个整数序列（可能有重复的整数），现删除指定的某一个整数，\
输出删除指定数字之后的序列，序列中未被删除数字的前后位置没有发生改变。


int main() {
	int N;
	while (scanf("%d", &N) != EOF)
	{
		int arr[20] = { 0 };
		int i = 0;
		for (i = 0; i < N; i++)
		{
			scanf("%d", &arr[i]);
		}
		int b = 0;
		scanf("%d", &b);
		int C = N;
		int D = N;
		while (N--)
		{
			if (arr[N] == b)
			{
				if (N == C - 1)
				{
					D--;
				}
				else
				{
					int E = C - N - 1;
					int F = N;
					while (E--)
					{
						arr[F] = arr[F + 1];
						F++;
					}
					D--;
				}
			}
		}
		for (i = 0; i < D; i++)
		{
			printf("%d ", arr[i]);
		}
	}
	return 0;
}

#include <stdio.h>//malloc模拟二维数组
#include <stdlib.h>
#include <assert.h>

int main()
{
	int* arr1 = (int*)malloc(5 * sizeof(int));
	int* arr2 = (int*)malloc(5 * sizeof(int));
	int* arr3 = (int*)malloc(5 * sizeof(int));
	assert(arr1 && arr2 && arr3);
	int* arr[] = { arr1,arr2,arr3 };
	int i = 0;
	int j = 0;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 5; j++)
		{
			arr[i][j] = i + j + 1;
		}
	}
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 5; j++)
		{
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
	return 0;
}

//在C.txt中读到   abcdefg
#include <stdio.h>//读文件--"r",fgetc,fgets,fscanf

int main()
{
	FILE* pf = fopen("C.txt", "r");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}

	//int ch = 0;
	//while ((ch = fgetc(pf)) != EOF)//int fgetc ( FILE * stream );
	//{
	//	printf("%c", ch);
	//}

	//char arr[20] = { 0 };
	//fgets(arr, 8, pf);//char * fgets ( char * str, int num, file * stream );
	//fgets读7个字符+'\0'
	//printf("%s", arr);

	//char arr[20] = { 0 };
	//fscanf(pf, "%s", arr);//int fscanf ( FILE * stream, const char * format, ... );
	//printf("%s", arr);

	fclose(pf);
	pf = NULL;
	return 0;
}

#include <stdio.h>//读文件--"rb",fread

int main()
{
	FILE* pf = fopen("C.txt", "rb");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}

	char arr[20] = { 0 };
	fread(arr, sizeof(arr[0]), 4, pf);//size_t fread(void* ptr, size_t size, size_t count, FILE* stream);
	int i = 0;
	for (i = 0; i < 4; i++)
	{
		printf("%c", arr[i]);
	}
 
	fclose(pf);
	pf = NULL;
	return 0;
}

//在C.txt中写  cf
#include <stdio.h>//写文件--"w",fputc,fputs,fprintf

int main()
{
	FILE* pf = fopen("C.txt", "w");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}

	//fputc('c', pf);//int fputc ( int character, FILE * stream );
	//fputc('f', pf);

	//fputs("cf", pf);//int fputs ( const char * str, FILE * stream );

	//fprintf(pf, "%s", "cf");//int fprintf ( FILE * stream, const char * format, ... );

	fclose(pf);
	pf = NULL;
	return 0;
}

#include <stdio.h>//写文件--"wb",fwrite

int main()
{
	FILE* pf = fopen("C.txt", "wb");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}

	char arr[] = "cfg";
	fwrite(arr, sizeof(arr[0]), 2, pf);//size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );

	fclose(pf);
	pf = NULL;
	return 0;
}

#include <stdio.h>//fseek,ftell,rewind

int main()
{
	FILE* pf = fopen("C.txt", "r");
	if (pf == NULL)
	{
		perror("fopen");
		return 1;
	}
	printf("%c", fgetc(pf));//a
	fseek(pf, 4, SEEK_CUR);//int fseek ( FILE * stream, long int offset, int origin );
	printf("%c", fgetc(pf));//f

	printf("%d", ftell(pf));//6//long int ftell ( FILE * stream );

	rewind(pf);
	printf("%c", fgetc(pf));//a//void rewind ( FILE * stream );

	fclose(pf);
	pf = NULL;
	return 0;
}

#include <stdio.h>//写一个程序拷贝文件

int main()
{
	FILE* pf1 = fopen("data.txt", "r");
	if (pf1 == NULL)
	{
		perror("fopen");
		return 1;
	}
	char arr[20] = { 0 };
	int count = 0;
	fgets(arr, 5, pf1);//char * fgets ( char * str, int num, FILE * stream );//4个加'\0'
	FILE* pf2 = fopen("data_copy.txt", "w");
	if (pf2 == NULL)
	{
		perror("fopen");
		return 2;
	}
	fputs(arr, pf2);//int fputs ( const char * str, FILE * stream );
	fclose(pf1);
	fclose(pf2);
	pf1 = NULL;
	pf2 = NULL;
	return 0;
}

#include <stdio.h>//预定义符号

int main()
{
	printf("%s\n", __FILE__);
	printf("%s\n", __DATE__);
	printf("%s\n", __DATE__);
	printf("%d\n", __LINE__);
	//printf("%d\n", __STDC__);//VS2022不遵循ANSI C
	return 0;
}

#include <stdio.h>//带有副作用的宏参数
#define MAX(a, b) ( (a) > (b) ? (a) : (b) )

int main()
{
	int x = 5;
	int y = 8;
	int z = MAX(x++, y++);
	printf("x=%d y=%d z=%d\n", x, y, z);

	return 0;
}

#include <stdio.h>// 宏参数和#define 定义中可以出现其他#define定义的符号
#define N 4
#define Y(n) ((N+2)*n)

int main()
{
	int z = 2 * (N + Y(5 + 1));
	printf("%d", z);
	return 0;
}

#include <stdio.h>// 当预处理器搜索#define定义的符号的时候，字符串常量的内容并不被搜索
#define N 4

int main()
{
	int z = 2 * N;
	printf("N = %d", z);
	return 0;
}

#include <stdio.h>//##,宏

//宏定义
#define GENERIC_MAX(type) \
type type##_max(type x, type y)\
{ \
 return (x>y?x:y); \
}

GENERIC_MAX(int) //替换到宏体内后int##_max 生成了新的符号 int_max做函数名
GENERIC_MAX(float) //替换到宏体内后float##_max 生成了新的符号 float_max做函数名
int main()
{
	//调用函数
	int m = int_max(2, 3);
	printf("%d\n", m);
	float fm = float_max(3.5f, 4.5f);
	printf("%f\n", fm);
	return 0;
}

条件编译

1.
#if 常量表达式(为真执行，为假不执行)
//...
#endif
//常量表达式由预处理器求值。
如：
#define __debug__ 1
#if __debug__
//..
#endif
2.多个分支的条件编译(效果和if,else if,else一样)
#if 常量表达式(为真执行，为假不执行)
//...
#elif 常量表达式(为真执行，为假不执行)
//...
#else
//...
#endif
3.判断是否被定义(仅仅判断是否定义(#define)，无论真假) 
#if defined(symbol) = #ifdef symbol
#if !defined(symbol) = #ifndef symbol
4.嵌套指令
#if defined(os_unix)
#ifdef option1
unix_version_option1();
#endif
#ifdef option2
unix_version_option2();
#endif
#elif defined(os_msdos)
#ifdef option2
msdos_version_option2();
#endif
#endif
最后都由#endif结束

#include <stdio.h>//环型列表 约瑟夫问题
#include <stdlib.h>

typedef struct ListNode
{
	int val;
	struct ListNode* next;
}ListNode;
//创建节点
ListNode* BuyNode(int x)
{
	ListNode* node = (ListNode*)malloc(sizeof(ListNode));
	if (node == NULL)
	{
		perror("node malloc");
		exit(1);
	}
	node->val = x;
	node->next = NULL;
	return node;
}
//创建不带头循环单链表
ListNode* CreateCircle(int n)
{
	ListNode* head = BuyNode(1);
	ListNode* ptail = head;
	int i = 0;
	for (i = 2; i <= n; i++)
	{
		ptail->next = BuyNode(i);
		ptail = ptail->next;
	}
	ptail->next = head;
	return ptail;//m为1时，需要知道尾节点的地址
}

int ysf(int n, int m)
{
	ListNode* prev = CreateCircle(n);//指向尾节点
	ListNode* pcur = prev->next;//指向第一个节点
	int count = 1;//pcur已经指向第一个节点
	while (pcur->next != pcur)
	{
		if (count != m)
		{
			prev = prev->next;
			pcur = pcur->next;
			count++;
		}
		else
		{
			prev->next = pcur->next;
			free(pcur);
			pcur = prev->next;
			count = 1;
		}
	}
	int ret = pcur->val;
	free(pcur);
	pcur = prev = NULL;
	return ret;
}
int main()
{
	int m, n;
	scanf("%d,%d", &m, &n);
	printf("%d", ysf(m, n));
	return 0;
}

#include <stdio.h>//旋转数组

void Reverse(int* right, int* left)
{
	int tmp = 0;
	while (right < left)
	{
		tmp = *right;
		*right = *left;
		*left = tmp;
		right++;
		left--;
	}
}

void rotate(int* nums, int numsSize, int k)
{
	k %= numsSize;
	Reverse(nums, nums + numsSize - k - 1);
	Reverse(nums + numsSize - k, nums + numsSize - 1);
	Reverse(nums, nums + numsSize - 1);
}

int main()
{
	int arr[7] = { 1,2,3,4,5,6,7 };
	rotate(arr, 7, 3);
	for (int i = 0; i < 7; i++)
	{
		printf("%d", arr[i]);
	}
	return 0;
}


//链表回文[1,2,2,1]
struct ListNode {

	int val;

	struct ListNode *next;

	ListNode(int x) : val(x), next(NULL) {}

};

class PalindromeList {

public:

	struct ListNode* reverseList(struct ListNode* head) {

		ListNode* ptail = head;

		if (!(ptail && ptail->next)) {

			return ptail;

		}

		ListNode* prev = ptail->next;

		ListNode* pcur = prev->next;

		while (1) {

			prev->next = ptail;

			ptail = prev;

			if (pcur == NULL) {

				break;

			}

			prev = pcur;

			pcur = pcur->next;

		}

		head->next = NULL;

		return ptail;

	}

	struct ListNode* middleNode(struct ListNode* head) {

		ListNode* faster = head;

		ListNode* slower = head;

		while ((faster != NULL) && (faster->next != NULL)) {

			faster = faster->next->next;

			slower = slower->next;

		}

		return slower;

	}

	bool chkPalindrome(struct ListNode* A) {

		struct ListNode* mid = middleNode(A);

		struct ListNode* rmid = reverseList(mid);

		while (A != mid)

		{

			if (A->val != rmid->val)

				return false;

			A = A->next;

			rmid = rmid->next;

		}

		return true;

	}

};
//#include <stdio.h>
//#include <stdlib.h>
//#include <assert.h>
//
//struct Node {
//	int val;
//	struct Node* next;
//	struct Node* random;
//};
//typedef struct Node Node;
//
//typedef struct Node Node;
//
//int Num(Node* p, Node* head)
//{
//	int count = 0;
//	Node* a = head;
//	while (1)
//	{
//		if (head->random == a)
//			return count;
//		count++;
//		a = a->next;
//	}
//}
//
//Node* Random(Node* p, Node* head)
//{
//	if (head->random == NULL)
//		return NULL;
//	int count = Num(p, head);
//	while (count--)
//	{
//		p = p->next;
//	}
//	return p;
//}
//
//Node* CreateNode(Node* head, int count)
//{
//	if (head == NULL)
//		return NULL;
//
//	Node* head1 = (Node*)malloc(sizeof(Node));
//	assert(head1);
//	Node* p = head1;
//
//	for (int i = 0; i < count - 1; i++)
//	{
//		p->next = (Node*)malloc(sizeof(Node));
//		assert(p->next);
//		p = p->next;
//	}
//	p->next = NULL;
//
//	Node* pp = head1;
//	for (int j = 0; j < count; j++)
//	{
//		pp->val = head->val;
//		pp->random = Random(pp, head);
//		head = head->next;
//		pp = pp->next;
//	}
//
//	return head1;
//}
//struct Node* copyRandomList(Node* head)
//{
//	Node* ptail = head;
//	int count = 0;
//	while (ptail)
//	{
//		ptail = ptail->next;
//		count++;
//	}
//	return CreateNode(head, count);
//}
//
//int main()
//{
//	Node* head = (Node*)malloc(sizeof(Node*));
//	assert(head);
//	head->next = NULL;
//	head->val = 5;
//	head->random = NULL;
//	copyRandomList(head);
//	return 0;
//}

#include <stdio.h>//offsetof宏

struct S
{
	char a;
	int b;
};
#define My_offsetof(s,m) ((size_t)&(((s*)0)->m))

int main()
{
	printf("%zd\n", My_offsetof(struct S, a));
	printf("%zd\n", My_offsetof(struct S, b));

	return 0;
}

#include <stdio.h>

#define Exchange(a) ((( (a) & 0x55555555) << 1 ) | ((( (a) & 0xaaaaaaaa) >> 1 )))
int main()
{
	int a = 14;
	printf("%d\n", Exchange(a));
	return 0;
}

//深拷贝

  Definition for a Node.

  struct Node {

      int val;

      struct Node *next;

      struct Node *random;

  };

 



struct Node* copyRandomList(struct Node* head) {

	struct Node* cur = head;

	if (cur == NULL)

	{

		return cur;

	}

	else

	{

		while (cur)

		{

			struct Node* Node = (struct Node*)malloc(sizeof(struct Node));

			Node->val = cur->val;

			Node->next = cur->next;

			cur->next = Node;

			cur = cur->next->next;

		}

		cur = head;

		while (cur)

		{

			if (cur->random == NULL)

			{

				cur->next->random = NULL;

			}

			else

			{

				cur->next->random = cur->random->next;

			}

			cur = cur->next->next;

		}

		cur = head;

		struct Node* head1 = cur->next;

		while (head1->next)

		{

			head1->next = head1->next->next;

			head1 = head1->next;

		}

		return cur->next;

	}

}

void ListInsert(ListNode* head, DataType x, DataType y)
{
	ListNode* p = head;
	ListNode* cur = head->next;
	while (cur != head)
	{
		if (cur->data == x)
		{
			ListNode* Y = (ListNode*)malloc(sizeof(ListNode));
			if (Y == NULL)
			{
				perror("ListInsert()::malloc()");
				return;
			}
			Y->data = y;
			Y->next = cur;
			Y->front = cur->front;
			cur->front->next = Y;
			cur->front = Y;
		}
		else
		{
			cur = cur->next;
		}
	}
}

//两个队列实现栈  空  非空
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <vld.h>

typedef int QDataType;
// 链式结构：表示队列 
typedef struct QListNode
{
	struct QListNode* _next;
	QDataType _data;
}QNode;

// 队列的结构 
typedef struct Queue
{
	QNode* _front;
	QNode* _rear;
	int size;
}Queue;

// 初始化队列 
void QueueInit(Queue* q)
{
	assert(q);
	q->_front = q->_rear = NULL;
	q->size = 0;
}

// 队尾入队列 
void QueuePush(Queue* q, QDataType data)
{
	assert(q);
	QNode* tmp = (QNode*)malloc(sizeof(QNode));
	if (tmp == NULL)
	{
		perror("QueueNode()::malloc()");
		return;
	}
	tmp->_next = NULL;
	tmp->_data = data;
	if (q->size == 0)
	{
		q->_front = q->_rear = tmp;
	}
	else
	{
		q->_rear->_next = tmp;
		q->_rear = tmp;
	}
	q->size++;
}

// 队头出队列 
void QueuePop(Queue* q)
{
	assert(q);
	if (q->size == 0)
	{
		printf("队列已空\n");
		return;
	}
	QNode* del = q->_front;
	q->_front = q->_front->_next;
	if (q->_front == NULL)
	{
		q->_rear = NULL;
	}
	free(del);
	del = NULL;
	q->size--;
}

// 获取队列头部元素 
QDataType QueueFront(Queue* q)
{
	assert(q);
	assert(q->_front);
	return q->_front->_data;
}

// 获取队列队尾元素 
QDataType QueueBack(Queue* q)
{
	assert(q);
	assert(q->_rear);
	return q->_rear->_data;
}

// 获取队列中有效元素个数 
int QueueSize(Queue* q)
{
	assert(q);
	return q->size;
}

// 检测队列是否为空，如果为空返回非零结果，如果非空返回0 
int QueueEmpty(Queue* q)
{
	assert(q);
	if (q->size == 0)
		return 1;
	else
		return 0;
}

// 销毁队列 
void QueueDestroy(Queue* q)
{
	while (q->_front)
	{
		QNode* del = q->_front;
		q->_front = q->_front->_next;
		free(del);
	}
	q->_rear = NULL;
	q->size = 0;
}

typedef struct {
	Queue Q1;
	Queue Q2;
} MyStack;


MyStack* myStackCreate() {
	MyStack* myStack = (MyStack*)malloc(sizeof(MyStack));
	assert(myStack);
	QueueInit(&(myStack->Q1));
	QueueInit(&(myStack->Q2));
	return myStack;
}

void myStackPush(MyStack* obj, int x) {
	if (obj->Q2.size != 0)
		QueuePush(&(obj->Q2), x);
	else
	    QueuePush(&(obj->Q1), x);
}

int myStackPop(MyStack* obj) {
	if (obj->Q1.size != 0)
	{
		while (obj->Q1.size != 0)
		{
			if (obj->Q1.size == 1)
				break;
			QueuePush(&(obj->Q2), QueueFront(&(obj->Q1)));
			QueuePop(&(obj->Q1));

		}
		int x = obj->Q1._front->_data;
		QueuePop(&(obj->Q1));
		return x;
	}
	else
	{
		while (obj->Q2.size != 0)
		{
			if (obj->Q2.size == 1)
				break;
			QueuePush(&(obj->Q1), QueueFront(&(obj->Q2)));
			QueuePop(&(obj->Q2));

		}
		int x = obj->Q2._front->_data;
		QueuePop(&(obj->Q2));
		return x;
	}
}

int myStackTop(MyStack* obj) {
	if (obj->Q1.size != 0)
	{
		while (obj->Q1.size != 0)
		{
			if (obj->Q1.size == 1)
				break;
			QueuePush(&(obj->Q2), QueueFront(&(obj->Q1)));
			QueuePop(&(obj->Q1));

		}
		int x = obj->Q1._front->_data;
		QueuePush(&(obj->Q2), QueueFront(&(obj->Q1)));
		QueuePop(&(obj->Q1));
		return x;
	}
	else
	{
		while (obj->Q2.size != 0)
		{
			if (obj->Q2.size == 1)
				break;
			QueuePush(&(obj->Q1), QueueFront(&(obj->Q2)));
			QueuePop(&(obj->Q2));

		}
		int x = obj->Q2._front->_data;
		QueuePush(&(obj->Q1), QueueFront(&(obj->Q2)));
		QueuePop(&(obj->Q2));
		return x;
	}
}

bool myStackEmpty(MyStack* obj) {
	if (QueueEmpty(&(obj->Q1)) && QueueEmpty(&(obj->Q2)))
		return true;
	else
		return false;
}

void myStackFree(MyStack* obj) {
	QueueDestroy(&(obj->Q1));
	QueueDestroy(&(obj->Q2));
	free(obj);
}

int main()
{
	MyStack* obj = myStackCreate();
	myStackPush(obj, 3);
	myStackPush(obj, 4);
	int param_2 = myStackPop(obj);
	int param_3 = myStackTop(obj);
	bool param_4 = myStackEmpty(obj);
	myStackFree(obj);
	return 0;
}

//两个队列实现栈  假设法  取队尾--栈顶  空  非空
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <vld.h>

typedef int QDataType;
// 链式结构：表示队列 
typedef struct QListNode
{
	struct QListNode* _next;
	QDataType _data;
}QNode;

// 队列的结构 
typedef struct Queue
{
	QNode* _front;
	QNode* _rear;
	int size;
}Queue;

// 初始化队列 
void QueueInit(Queue* q)
{
	assert(q);
	q->_front = q->_rear = NULL;
	q->size = 0;
}

// 队尾入队列 
void QueuePush(Queue* q, QDataType data)
{
	assert(q);
	QNode* tmp = (QNode*)malloc(sizeof(QNode));
	if (tmp == NULL)
	{
		perror("QueueNode()::malloc()");
		return;
	}
	tmp->_next = NULL;
	tmp->_data = data;
	if (q->size == 0)
	{
		q->_front = q->_rear = tmp;
	}
	else
	{
		q->_rear->_next = tmp;
		q->_rear = tmp;
	}
	q->size++;
}

// 队头出队列 
void QueuePop(Queue* q)
{
	assert(q);
	if (q->size == 0)
	{
		printf("队列已空\n");
		return;
	}
	QNode* del = q->_front;
	q->_front = q->_front->_next;
	if (q->_front == NULL)
	{
		q->_rear = NULL;
	}
	free(del);
	del = NULL;
	q->size--;
}

// 获取队列头部元素 
QDataType QueueFront(Queue* q)
{
	assert(q);
	assert(q->_front);
	return q->_front->_data;
}

// 获取队列队尾元素 
QDataType QueueBack(Queue* q)
{
	assert(q);
	assert(q->_rear);
	return q->_rear->_data;
}

// 获取队列中有效元素个数 
int QueueSize(Queue* q)
{
	assert(q);
	return q->size;
}

// 检测队列是否为空，如果为空返回非零结果，如果非空返回0 
int QueueEmpty(Queue* q)
{
	assert(q);
	if (q->size == 0)
		return 1;
	else
		return 0;
}

// 销毁队列 
void QueueDestroy(Queue* q)
{
	while (q->_front)
	{
		QNode* del = q->_front;
		q->_front = q->_front->_next;
		free(del);
	}
	q->_rear = NULL;
	q->size = 0;
}

typedef struct {
	Queue Q1;
	Queue Q2;
} MyStack;


MyStack* myStackCreate() {
	MyStack* myStack = (MyStack*)malloc(sizeof(MyStack));
	assert(myStack);
	QueueInit(&(myStack->Q1));
	QueueInit(&(myStack->Q2));
	return myStack;
}

void myStackPush(MyStack* obj, int x) {
	if (obj->Q2.size != 0)
		QueuePush(&(obj->Q2), x);
	else
		QueuePush(&(obj->Q1), x);
}

int myStackPop(MyStack* obj) {
	//这里是使obj里的Q1，Q2改变，而不是复制一份，除了函数就没了
	Queue* empty = &(obj->Q1);
	Queue* noempty = &(obj->Q2);
	if (QueueEmpty(&(obj->Q2)))
	{
		empty = &(obj->Q2);
		noempty = &(obj->Q1);
	}
	while (noempty->size != 1)
	{
		QueuePush(empty, QueueFront(noempty));
		QueuePop(noempty);
	}
	int x = noempty->_front->_data;
	QueuePop(noempty);
	return x;
}

int myStackTop(MyStack* obj) {
	if (!QueueEmpty(&(obj->Q1)))
		return obj->Q1._rear->_data;
	else
		return obj->Q2._rear->_data;
}

bool myStackEmpty(MyStack* obj) {
	if (QueueEmpty(&(obj->Q1)) && QueueEmpty(&(obj->Q2)))
		return true;
	else
		return false;
}

void myStackFree(MyStack* obj) {
	QueueDestroy(&(obj->Q1));
	QueueDestroy(&(obj->Q2));
	free(obj);
}

int main()
{
	MyStack* obj = myStackCreate();
	myStackPush(obj, 3);
	myStackPush(obj, 4);
	int param_2 = myStackPop(obj);
	int param_3 = myStackTop(obj);
	bool param_4 = myStackEmpty(obj);
	myStackFree(obj);
	return 0;
}

//两个栈实现队列  push  pop
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <vld.h>
typedef int STDataType;
typedef struct Stack
{
	STDataType* _a;
	int _top;		// 栈顶
	int _capacity;  // 容量 
}Stack;

// 初始化栈 
void StackInit(Stack* ps)
{
	assert(ps);
	ps->_a = NULL;
	ps->_top = ps->_capacity = 0;
}

//动态申请
void Stackcapacity(Stack* ps)
{
	if (ps->_top == ps->_capacity)
	{
		ps->_capacity = ps->_capacity == 0 ? 4 : 2 * ps->_capacity;
		STDataType* tmp = (STDataType*)realloc(ps->_a, ps->_capacity * sizeof(STDataType));
		if (tmp == NULL)
		{
			perror("Stackcapacity()::realloc()");
			return;
		}
		ps->_a = tmp;
	}
}

// 入栈 
void StackPush(Stack* ps, STDataType data)
{
	assert(ps);
	Stackcapacity(ps);//动态申请
	ps->_a[ps->_top] = data;
	ps->_top++;
}

// 出栈 
void StackPop(Stack* ps)
{
	assert(ps);
	if (ps->_top == 0)
	{
		printf("栈已空\n");
		return;
	}
	ps->_top--;
}

// 获取栈顶元素 
STDataType StackTop(Stack* ps)
{
	assert(ps);
	assert(ps->_top != 0);
	return ps->_a[ps->_top - 1];
}

// 获取栈中有效元素个数 
int StackSize(Stack* ps)
{
	assert(ps);
	return ps->_top;
}

// 检测栈是否为空，如果为空返回非零结果，如果不为空返回0 
int StackEmpty(Stack* ps)
{
	assert(ps);
	if (ps->_top == 0)
		return 1;
	else
		return 0;
}

// 销毁栈 
void StackDestroy(Stack* ps)
{
	assert(ps);
	free(ps->_a);
	ps->_a = NULL;
	ps->_top = ps->_capacity = 0;
}

typedef struct {
	Stack push;
	Stack pop;
} MyQueue;


MyQueue* myQueueCreate() {
	MyQueue* s = (MyQueue*)malloc(sizeof(MyQueue));
	assert(s);
	StackInit(&(s->push));
	StackInit(&(s->pop));
	return s;
}

void myQueuePush(MyQueue* obj, int x) {
	StackPush(&(obj->push), x);
}

int myQueuePeek(MyQueue* obj) {
	if (StackEmpty(&(obj->pop)))
	{
		while (!StackEmpty(&(obj->push)))
		{
			StackPush(&(obj->pop), StackTop(&(obj->push)));
			StackPop(&(obj->push));
		}
	}
	return StackTop(&(obj->pop));
}

int myQueuePop(MyQueue* obj) {
	int x = myQueuePeek(obj);
	StackPop(&(obj->pop));
	return x;
}



bool myQueueEmpty(MyQueue* obj) {
	if (StackEmpty(&(obj->push) )&& StackEmpty(&(obj->pop)))
	{
		return true;
	}
	else
		return false;
}

void myQueueFree(MyQueue* obj) {
	StackDestroy(&(obj->push));
	StackDestroy(&(obj->pop));
	free(obj);
}

int main()
{
	MyQueue* obj = myQueueCreate();
	myQueuePush(obj, 1);
	myQueuePush(obj, 2);
	int a = myQueuePeek(obj);
	int b = myQueuePop(obj);
	myQueueEmpty(obj);
	myQueueFree(obj);
	return 0;
}

//循环队列  循环  获取队位元素
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <vld.h>
typedef struct {
	int* arr;
	int front;
	int rear;
	int count;
	int k;
} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) {
	MyCircularQueue* Q = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
	assert(Q);
	Q->arr = (int*)malloc(sizeof(int) * k);
	Q->front = Q->rear = Q->count = 0;
	Q->k = k;
	return Q;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
	if (obj->count != 0 && obj->front == obj->rear)
		return true;
	else
		return false;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
	if (obj->count == 0)
		return true;
	else
		return false;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
	if (myCircularQueueIsFull(obj))
		return false;
	obj->arr[(obj->rear)] = value;
	obj->rear = (obj->rear + 1) % obj->k;
	obj->count++;
	return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
	if (myCircularQueueIsEmpty(obj))
		return false;
	obj->front = (obj->front + 1) % obj->k;
	obj->count--;
	return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
	if (myCircularQueueIsEmpty(obj))
		return -1;
	else
		return obj->arr[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj) {
	if (myCircularQueueIsEmpty(obj))
		return -1;
	else
		return obj->arr[(obj->rear + obj->k - 1) % obj->k];
}

void myCircularQueueFree(MyCircularQueue* obj) {
	free(obj->arr);
	free(obj);
}

int main()
{
	MyCircularQueue* obj = myCircularQueueCreate(3);
	bool a = myCircularQueueEnQueue(obj, 1);
	bool b = myCircularQueueEnQueue(obj, 2);
	bool c = myCircularQueueEnQueue(obj, 3);
	bool d = myCircularQueueEnQueue(obj, 4);

	int r1 = myCircularQueueRear(obj);

	bool f = myCircularQueueIsFull(obj);

	bool de = myCircularQueueDeQueue(obj);

	bool e = myCircularQueueEnQueue(obj, 4);

	int r2 = myCircularQueueRear(obj);

	//int param_3 = myCircularQueueFront(obj);

	//bool param_5 = myCircularQueueIsEmpty(obj);

	myCircularQueueFree(obj);
	return 0;
}

//文件函数 
#include <stdio.h>

typedef struct
{
	char name[20];
	int age;
}Person;

//写文件 文本 
void writePerson1(const char* filename, const Person* person, const char* mode)
{
	FILE* fp = fopen(filename, mode);
	if (fp == NULL)
	{
		perror("writePerson1()::fopen()");
		return;
	}
	fprintf(fp, "%s %d\n", person->name, person->age);
	fclose(fp);
	return;
}

//读文件 文本 
void readPersons1(const char* filename)
{
	FILE* fp = fopen(filename, "r");
	if (fp == NULL)
	{
		perror("readPersons1()::fopen()");
		return;
	}
	Person person;
	while (fscanf(fp, "%s%d", person.name, &(person.age)) == 2)//if的话，只能打印一个人 
	{
		printf("Name:%s,Age:%d\n", person.name, person.age);
	}
	fclose(fp);
}

//写文件 二进制 
void writePerson2(const char* filename, const Person* person, const char* mode)
{
	FILE* fp = fopen(filename, mode);
	if (fp == NULL)
	{
		perror("writePerson2()::fopen()");
		return;
	}
	fwrite(person, sizeof(*person), 1, fp);
	fclose(fp);
}

//读文件 二进制 
void readPersons2(const char* filename)
{
	FILE* fp = fopen(filename, "rb");
	if (fp == NULL)
	{
		perror("readPersons2()::fopen()");
		return;
	}
	Person person;
	while (fread((&person), sizeof(Person), 1, fp) == 1)
	{
		printf("Name:%s,Age:%d\n", person.name, person.age);
	}
	fclose(fp);
}

int main()
{
	Person p1 = { "Alice",30 }, p2 = { "Bob",25 }, p3 = { "zhangsan",12 };
	const char* filename1 = "example.txt";
	const char* filename2 = "example.dat";

	//	writePerson1(filename1,&p1,"w");
	//	writePerson1(filename1,&p2,"a");
	//	readPersons1(filename1);

	writePerson2(filename2, &p1, "wb");
	writePerson2(filename2, &p2, "ab");
	writePerson2(filename2, &p3, "ab");
	readPersons2(filename2);
	//feek,ftell,rewind
	FILE* fp = fopen(filename2, "rb+");
	if (fp == NULL)
	{
		perror("main()::fopen()");
		return -1;
	}

	Person person;

	//读取第一个记录
	fread(&person, sizeof(Person), 1, fp);
	printf("第一个记录：%s %d\n", person.name, person.age);

	//使用ftell获取当前位置
	long int pos = ftell(fp);
	printf("当前位置：第%ld个字节\n", pos);

	//使用ftell跳转到第二个记录
	fseek(fp, sizeof(Person), SEEK_SET);
	fread(&person, sizeof(Person), 1, fp);
	printf("第二个记录：%s %d\n", person.name, person.age);

	//使用rewind重置文件指针到开头 
	rewind(fp);
	fread(&person, sizeof(Person), 1, fp);
	printf("重置到文件开头：%s %d\n", person.name, person.age);

	//修改第二条数据
	fseek(fp, sizeof(Person), SEEK_SET);
	fread(&person, sizeof(Person), 1, fp);
	person.age = 18;
	fseek(fp, sizeof(Person), SEEK_SET);
	fwrite(&person, sizeof(Person), 1, fp);

	//修改后的文件 
	readPersons2(filename2);

	fclose(fp);
	return 0;
}

#include <stdio.h>
#include <string.h>

void writefile(const char* filename, const char* mode)
{
	FILE* fp = fopen(filename, mode);
	if (fp == NULL)
	{
		perror("writefile()::fopen()");
		return;
	}
	char* arr = "hello    world\tand\n we are family";
	fprintf(fp, "%s", arr);
	fclose(fp);
}

void readfile(const char* filename)
{
	FILE* fp = fopen(filename, "r");
	if (fp == NULL)
	{
		perror("readfile()::fopen()");
		return;
	}
	char arr[100];
	int count = 0;
	while (fscanf(fp, "%s", arr) == 1)
		count++;
	printf("单词个数:%d个\n", count);
	fclose(fp);
}

int main()
{
	const char* filename = "example1.txt";
	writefile(filename, "w");
	readfile(filename);
	return 0;
}
*/
//#include <stdio.h>
//#include <string.h>
//
//void copyfile(const char* filename1, const char* filename2)
//{
//	FILE* fp1 = fopen(filename1, "r");
//	FILE* fp2 = fopen(filename2, "wb+");
//	if (fp1 == NULL || fp2 == NULL)
//	{
//		perror("copyfile()::fopen()");
//		return;
//	}
//	int ch;
//	int i = 0;
//	char arr[100] = { 0 };
//	while ((ch = fgetc(fp1)) != EOF)
//	{
//		arr[i] = (char)ch;
//		++i;
//	}
//	fwrite(arr, strlen(arr)+sizeof(char), 1, fp2);
//	char a[100] = {0};
//	fread(a, strlen(arr) + sizeof(char), 1, fp2);
//	printf("%c", a[0]);
//	fclose(fp1);
//	fclose(fp2);
//}
//
//int main()
//{
//	const char* filename1 = "example1.txt";
//	const char* filename2 = "example2.dat";
//	copyfile(filename1, filename2);
//
//	return 0;
//}

#include <stdio.h>

int main()
{
	int arr[m][n] = { 1,2,3,4,5,6,7,8,9,10,11,12 };
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m;j++)
		{
			printf("%d ", arr[m - j - 1][i]);
		}
		printf("\n");
	}
	return 0;
}